w1 = 50
metal1 = [(10, 100), (50, 30), (7, 34), (87, 100)]

w2 = 10000
metal2 = [(1, 43), (43, 323), (35, 45), (43, 54), (87, 43)]

def calcMetalInfo(lst):
    return [(item[0], item[1] / item[0]) for item in lst]

info1 = calcMetalInfo(metal1)
info2 = calcMetalInfo(metal2)

def theValue(info):
    return info[1]

info1.sort(key=theValue, reverse=True)
info2.sort(key=theValue, reverse=True)
print(info1)
print(info2)

def calcTotalValue(w, info):
    v = 0

    # for i, item in enumerate(info):
    for item in info:
        if w >= item[0]:
            v += item[1] * item[0]
            w -= item[0]
        else:
            v += item[1] * w
            w = 0

    return v

print(calcTotalValue(w1, info1))
print(calcTotalValue(w2, info2))
